<?php

namespace App\Exports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;

class stationsExport implements FromCollection
{
    private array $data;

    public function __construct(array $data)
    {
        $this->data = $data;
    }

    /**
     * @return Collection
     */
    public function collection()
    {
        $this->data = collect($this->data)->map(function ($station) {
            return [
                "station_name"    => $station['station_name'] ?? '',
                "station_code"    => $station['station_code'] ?? '',
                "pinyin"          => $station['pinyin'] ?? '',
                "abbr"            => $station['abbr'] ?? '',
                "initial"         => $station['initial'] ?? '',
                "station_name_uy" => $station['station_name_uy'] ?? '',
                "initial_uy"      => $station['initial_uy'] ?? '',
            ];
        })->toArray();
        $head       = ["站点名称", "code", "拼音", "abbr", "首字母", "维语", "维语首字母"];
        array_unshift($this->data, $head);
        return collect($this->data);
    }
}
